package com.goods.controller.business;

import com.goods.business.service.IConsumerService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ConsumerVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 *
 * @Date: 2023/3/6 - 17:57
 * @Author: Hyoung
 * @Description:
 */
//ttp://www.localhost:8989/business/consumer/findAll
@RestController
@RequestMapping("/business/consumer")
public class ConsumerController {

    @Autowired
    private IConsumerService iConsumerService;

    @GetMapping("/findAll")
    public ResponseBean findAllConsumer() {
        List<ConsumerVO> consumerVOList = iConsumerService.findAllConsumer();
        return ResponseBean.success(consumerVOList);
    }

    // /business/consumer/findConsumerList?pageNum=1&pageSize=10&
    @GetMapping("/findConsumerList")
    public ResponseBean findConsumerList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize") Integer pageSize,
                                         ConsumerVO consumerVO) {
        PageVO<ConsumerVO> pageVO = iConsumerService.findConsumerList(pageNum, pageSize, consumerVO);
        return ResponseBean.success(pageVO);
    }


    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Integer id) {
        iConsumerService.delete(id);
        return ResponseBean.success();
    }

    ///business/inStock/addIntoStock
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Integer id) {
        ConsumerVO consumerVO = iConsumerService.findConsumerById(id);
        return ResponseBean.success(consumerVO);
    }

    @PutMapping("/update/{id}")
    public ResponseBean updateConsumer(@PathVariable Integer id,
                                       @RequestBody ConsumerVO consumerVO) {
        System.out.println(consumerVO);
        iConsumerService.updateConsumer(id, consumerVO);
        return ResponseBean.success();
    }


    @PostMapping("/add")
    public ResponseBean addConsumer(@RequestBody ConsumerVO consumerVO) {
        iConsumerService.addConsumer(consumerVO);
        return ResponseBean.success();

    }
}


